package com.cn.wxwinnie.java.datatype.string;

/**
 * @author 潇湘暮雨 E-mail:wxwinnie@hotmail.com
 * 
 * @version 创建时间：2014年3月29日 下午2:58:28
 * 
 */
public class TestString {

	public static void main(String[] args) {

		String hello = "hello";
		String hel = "hel";
		String helloc = hel + "lo";

		String xyz = "x" + "y" + "z";
		// 这种通过运行时计算出来的字符串是不一样的，是新创建的对象的
		System.out.println("hello == (hel + \"lo\"): " + (hello == (hel + "lo")));
		// 这里的xyz 虽然也是字符串拼接出来的，但是不是运行时，是编译时创建的。
		System.out.println("xyz == \"xyz\": " + (xyz == "xyz")); 
		System.out.println("hello == helloc: " + (hello == helloc));

		// Returns a canonical representation for the string object.
		// A pool of strings, initially empty, is maintained privately by the
		// class String.
		// When the intern method is invoked, if the pool already contains a
		// string equal to this String object as determined by the
		// equals(Object) method, then the string from the pool is returned.
		// Otherwise, this String object is added to the pool and a reference to
		// this String object is returned.
		// It follows that for any two strings s and t, s.intern() == t.intern()
		// is true if and only if s.equals(t) is true.
		System.out.println("helloc.intern() " + helloc.intern());
	}

}
